package cn.com.jslh.boarpro.main;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.main.presenter.MainPresenterImpl;
import cn.com.jslh.boarpro.main.view.view.MainView;
import cn.com.jslh.boarpro.util.WebService;

public class MainActivity extends AppCompatActivity implements MainView, Toolbar.OnMenuItemClickListener {
    @BindView(R.id.recycleview)
    RecyclerView recycleview;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.title)
    TextView mtitle;
    @BindView(R.id.layout_main)
    LinearLayout layout;

    private MainPresenterImpl mainPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
//        setSupportActionBar(toolbar);
        toolbar.inflateMenu(R.menu.menu_main);

        toolbar.setOnMenuItemClickListener(this);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
        recycleview.setLayoutManager(gridLayoutManager);
//        recycleview.addItemDecoration(new DividerGridItemDecoration(this));
        mainPresenter = new MainPresenterImpl(this, this);
        mainPresenter.setUI(recycleview);
        mainPresenter.upDatas();
        mainPresenter.initBaseData();
        mainPresenter.getJbData();
    }

    @Override
    public void onItemClicked(String... params) {

    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_edit:
                Toast.makeText(this, "切换生产条线", Toast.LENGTH_SHORT).show();
                mainPresenter.setStripline(layout);
                break;
        }
        return true;
    }

    @Override
    public void setTitle(String title) {
        mtitle.setText(title);
    }


    @Override
    protected void onDestroy() {
//        mainPresenter.loginOut(new WebService.NetSuccessListener() {
//            @Override
//            public void Success(String s) throws JSONException {
//            }
//        });
        super.onDestroy();
    }

}
